package router

import (
	"entrytask/handler"
	"entrytask/router/middleware"
	"github.com/gin-gonic/gin"
	"net/http"
)

// InitRouter 初始化路由
func InitRouter(g *gin.Engine) {
	middlewares := []gin.HandlerFunc{}
	// Middlewares.
	g.Use(gin.Recovery())
	g.Use(middleware.NoCache)
	g.Use(middleware.Options)
	g.Use(middleware.Secure)
	g.Use(middlewares...)
	// 404 Handler.
	g.NoRoute(func(c *gin.Context) {
		c.String(http.StatusNotFound, "404 not found！.")
	})

	// The health check handlers
	router := g.Group("/user")
	{
		router.GET("/name/query", handler.QueryUserByName)   // 查询用户
		router.GET("/token/query", handler.QueryUserByToken) // 查询用户
		router.POST("/login", handler.LoginUser)             // 用户登陆
		router.POST("/update", handler.UpdateUser)           // 用户更新
		router.POST("/add", handler.AddUser)                 // 添加用户
	}

}
